package com.shen.thread.demo1;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class TestThread2 extends Thread {
    private String url;//图片地址
    private String name;//文件名

    public TestThread2(String url, String name) {
        this.url = url;
        this.name = name;
    }

    @Override
    public void run() {
        WebDownLoading webDownLoader = new WebDownLoading();
        webDownLoader.downloader(url, name);
        System.out.println("下载文名" + name);
    }

    public static void main(String[] args) {
        TestThread2 t1 = new TestThread2("https://bkimg.cdn.bcebos.com/pic/b8014a90f603738da97755563251a751f81986184626?x-bce-process=image/resize,m_lfit,w_268,limit_1/format,f_jpg", "1.jpg");
        TestThread2 t2 = new TestThread2("https://bkimg.cdn.bcebos.com/pic/b8014a90f603738da97755563251a751f81986184626?x-bce-process=image/resize,m_lfit,w_268,limit_1/format,f_jpg", "2.jpg");

        t1.start();
        t2.start();

    }
}

class WebDownLoading {
    public void downloader(String url, String name) {
        try {
            FileUtils.copyURLToFile(new URL(url), new File(name));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("io异常，download");
        }
    }
}